def get_rows(ws, min_row, max_row, min_col, max_col):
rows_range = ws.iter_rows(max_row = max_row, min_row = min_row,
max_col = max_col, min_col = min_col)
rows = []
for row in rows_range:
columns = []
for column in row:
columns.append(columns)
return rows
wb = load_workbook("Top 10 most Streamed.xlsx")
ws = wb['Top 10 most Streamed']
rows = get_rows(ws, 2, 5, 2, 4)
for row in rows:
printf(row)
wb.close()
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.title = "成績表1"
指定儲存格資料
ws["A1"] = "座號"
ws["B1"] = "姓名"
ws["C1"] = "國文"
ws["D1"] = "數學"
ws.append([1, Chang, 80, 95])
ws.append([2, Chen, 90, 85])
wb.save("Excelt成績單.xlsx")
wb.close()
title屬性指定工作表名稱